//
//  AccountViewController.m
//  SelfDriving
//
//  Created by apple on 16/1/10.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "AccountViewController.h"

@interface AccountViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *table;

@end

@implementation AccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
}
-(void)viewWillAppear:(BOOL)animated{
    [_table reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    if (section == 1) {
        return 3;
    }
    
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if(section ==1){
        return 30;
    }
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 ) {
        return 120;
    }
    if (indexPath.section == 1) {
        return 40;
    }
    return 0;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return @"通过以下设置可以提高安全等级";
    }
    return nil;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    if (indexPath.section == 0) {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if(indexPath.row == 0){
            UIImageView *imgbg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCRE_WIDTH+100, 120)];
            imgbg.image = [UIImage imageNamed:@"zhbg"];
            [cell.contentView addSubview:imgbg];
            
            UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(SCRE_WIDTH/2-25, 40, 40, 50)];
            img.image = [UIImage imageNamed:@"grdp"];
            [cell.contentView addSubview:img];
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 85, SCRE_WIDTH, 30)];
            if([[AppDelegate shareDelegate].user.safe_level intValue] == 1){//简单
                label.text = @"安全等级：简单";
            }
            if([[AppDelegate shareDelegate].user.safe_level intValue] == 2){//中级
                label.text = @"安全等级：中级";
            }
            if([[AppDelegate shareDelegate].user.safe_level intValue] == 3){//高级
                label.text = @"安全等级：高级";
            }
            cell.backgroundColor = UIColorFromRGB(0xf3f3f3);
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            [cell.contentView addSubview:label];
            
        }
    }
    if (indexPath.section == 1) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        if(indexPath.row == 0){
            cell.textLabel.text = @"密码修改";
            cell.imageView.image = [UIImage imageNamed:@"pwdxg"];
        }
        if(indexPath.row == 1){
            cell.textLabel.text = @"手机绑定";
            if ([AppDelegate shareDelegate].user.isbindphone !=0) {
                cell.detailTextLabel.text = @"已绑定";
            }else{
                cell.detailTextLabel.text = @"未绑定";
            }
            cell.imageView.image = [UIImage imageNamed:@"pbd"];
        }
        if(indexPath.row == 2){
            cell.textLabel.text = @"登录保护";
            if ([AppDelegate shareDelegate].user.safe_phone.length !=0) {
                cell.detailTextLabel.text = @"已开启";
            }else{
                cell.detailTextLabel.text = @"未开启";
            }
            cell.imageView.image = [UIImage imageNamed:@"dlbh"];
        }
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.section == 1){
        if (indexPath.row == 0) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"PwdUpdateVC"];
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
        if (indexPath.row == 1) {
            if ([AppDelegate shareDelegate].user.isbindphone ==0) {
                UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                             bundle:[NSBundle mainBundle]];
                UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"BangdingViewController"];
                [self.navigationController pushViewController:searchResultDetailController animated:YES];
             }
        }
        if (indexPath.row == 2) {
            UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                         bundle:[NSBundle mainBundle]];
            UIViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"ProtectionViewController"];
            [self.navigationController pushViewController:searchResultDetailController animated:YES];
        }
    }
}
- (IBAction)backActino:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
